package acom.test.swing.aa;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

public class ExcelUtil {

	static List<AnswerPeople> peoples = new ArrayList<AnswerPeople>();
	
	public static void main(String[] args) {
		
		String excel_file = "E:\\libs\\jxl\\1369126619909.xls";
		
		
	}
	
	public static List<AnswerPeople> readExcelFile(String filename){						
		File file = new File(filename);
		return readExcelFile(file);
	}
	
	public static List<AnswerPeople> readExcelFile(File file){
		try {
			InputStream is = new FileInputStream(file); 
			Workbook workbook = Workbook.getWorkbook(is);
												
			//获取第一张Sheet表
			Sheet sheet = (Sheet) workbook.getSheet(0);						
			
			int row=sheet.getRows();
			int col=sheet.getColumns();
			
			Cell c=null;
			for(int i=1;i<row;i++){
				AnswerPeople people = new AnswerPeople();
				for(int j=0;j<col;j++){					
					c=sheet.getCell(j,i);
					String content = c.getContents();
					putInPeople(people,content,j);
				}
				peoples.add(people);
			}
			
			for(AnswerPeople p: peoples){
				System.out.println("==>"+p.toString());
			}
			
			workbook.close();						
		} catch (Exception e) {			
			e.printStackTrace();
		} 
		
		return peoples;
	}

	private static void putInPeople(AnswerPeople people, String content, int j) {
		
		switch(j){
		case 0 : 
			people.setId(content);
			break;
		case 1 : 
			people.setPaperId(content);
			break;
		case 2 : 
			people.setPeopleName(content);
			break;
		case 3 : 
			people.setPeoCorpType(content);
			break;
		case 4 : 
			people.setPeoTel(content);
			break;
		case 5 : 
			people.setMailNo(content);
			break;
		case 6 : 
			people.setAddress(content);
			break;
		case 7 : 
			people.setCorrectCount(Integer.parseInt(content));
			break;		
        default : 
        	System.out.println(" default ");
		}
		
	}

}
